package com.qdsg.ysg.doctor.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseDialogFragment;
import com.qdsg.ysg.doctor.util.AES128;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.qdsg.ysg.doctor.util.UtilString;
import com.rest.business.RestProxy;
import com.rest.response.BaseResponse;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


/**
 * Created by HP on 2018/10/5.
 */

public class SendSmsDialog extends BaseDialogFragment {

    private String type;

    public static SendSmsDialog newInstance(String type) {
        Bundle args = new Bundle();
        args.putString( "type", type );
        SendSmsDialog fragment = new SendSmsDialog();
        fragment.setArguments( args );
        return fragment;
    }

    private Dialog mDialog;
    private OnItemClickListener mListener;
    private TextView btn_confirm, btn_cancel, tv_message, tv_sms_title;

    @SuppressLint("WrongViewCast")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate( R.layout.dialog_code, container );
        btn_confirm = view.findViewById( R.id.btn_confirm );
        btn_cancel = view.findViewById( R.id.btn_cancel );
        tv_message = view.findViewById( R.id.tv_message );
        tv_sms_title = view.findViewById( R.id.tv_sms_title );

        if (getArguments() != null) {
            type = getArguments().getString( "type" );
        }

        if ("1".equals( type )) {
            tv_sms_title.setText( "通知患者报道" );
            tv_message.setText( "您确定要发送一条通知患者报道的信息?" );
        } else if ("2".equals( type )) {
            tv_sms_title.setText( "通知患者上线" );
            tv_message.setText( "您确定要发送一条通知患者上线的信息?" );
        } else if ("3".equals( type )) {
            tv_sms_title.setText( "通知患者确认处方" );
            tv_message.setText( "您确定要发送一条通知患者确认处方的信息?" );
        }
        btn_cancel.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onCancel();
                    dismiss();
                }
            }
        } );

        btn_confirm.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onConfirm();
                    dismiss();

                }
            }
        } );
        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );


    }

    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = super.onCreateDialog( savedInstanceState );
        mDialog.setCancelable( false );
        Window window = mDialog.getWindow();
        if (window != null) {
            window.setGravity( Gravity.CENTER );
//            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        return mDialog;
    }

    String message;

    public void setText(String message) {
        this.message = message;

    }


    public void setInfo() {
        tv_message.setText( message );
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        getDialog().getWindow().requestFeature( Window.FEATURE_NO_TITLE );
        super.onActivityCreated( savedInstanceState );
        getDialog().getWindow().setBackgroundDrawable( new ColorDrawable( 0x00000000 ) );
        getDialog().getWindow().setLayout( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT );
    }

    public OnItemClickListener getmListener() {
        return mListener;
    }

    public void setmListener(OnItemClickListener mListener) {
        this.mListener = mListener;
    }


    public interface OnItemClickListener {

        void onConfirm();

        void onCancel();
    }

    public boolean isShowing() {
        return mDialog != null && mDialog.isShowing();
    }

}
